package com.sziit.se.highconcurrency.application.controller;


import com.sziit.se.highconcurrency.application.service.IUserService;
import com.sziit.se.highconcurrency.common.annotation.IgnoreCheck;
import com.sziit.se.highconcurrency.common.result.Result;
import com.sziit.se.highconcurrency.common.result.ResultUtil;
import com.sziit.se.highconcurrency.tool.PrintThreadInfo;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dongchunkeng
 * @since 2022-09-21
 */
@RestController
@RequestMapping("/application/user")
@AllArgsConstructor
public class UserController {

    private final IUserService userService;

    @GetMapping
    @IgnoreCheck
    public Result getExampleInfo() throws InterruptedException {
        PrintThreadInfo.printThreadInfo();
        return ResultUtil.data(userService.getAllData());
    }

    @PostMapping
    @IgnoreCheck
    public Result addUserInfo(
            @NotBlank(message = "userName为空")String userName,
            @NotBlank(message = "phone为空")String phone
    ){
        return ResultUtil.auto(userService.insertUser(userName,phone));
    }

}
